package com.gao.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @description: 返回信息对象
 * @author: anshenghui
 * @create: 2020-04-07 15:02
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;

    private T result;

    private String message;

    private long total;

    public static com.gao.base.Result success(Object o) {
        com.gao.base.Result result = new com.gao.base.Result();
        result.setCode("200");
        result.setResult(o);
        result.setMessage("操作成功！");
        return result;
    }

    public static com.gao.base.Result success() {
        com.gao.base.Result result = new com.gao.base.Result();
        result.setCode("200");
        result.setMessage("操作成功！");
        return result;
    }

    public static com.gao.base.Result error() {
        com.gao.base.Result result = new com.gao.base.Result();
        result.setCode("500");
        result.setMessage("操作失败！");
        return result;
    }

    public static com.gao.base.Result successIpage(IPage page) {
        com.gao.base.Result result = new com.gao.base.Result();
        result.setCode("200");
        result.setResult(page.getRecords());
        result.setTotal(page.getTotal());
        result.setMessage("操作成功！");
        return result;
    }

    public static com.gao.base.Result error(String message) {
        com.gao.base.Result result = new com.gao.base.Result();
        result.setCode("500");
        result.setMessage(message);
        return result;
    }

}
